{% extends 'back/public/basetop.html' %}

{% block title %}会员信息{% endblock %}
{% block mycss %}
<link rel="stylesheet" href="/static/back/css/weadmin.css">
{% endblock %}

{% block currpath %}会员信息{% endblock %}
{% block contains%}
<div class="weadmin-body">
  <!---会员信息区域Start-->
    <form class="layui-form layui-form-pane" method="post" id="addform" lay-filter="addform">
        {% csrf_token %}
        <div class="layui-row">
            <div class="layui-form-item">
                <label class="layui-form-label"><i style="color:red;">*</i>&nbsp;栏目名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="t_name" lay-verify="required|title" autocomplete="off" placeholder="请输入栏目名称" class="layui-input">
                </div>
                 <div class="layui-form-mid layui-word-aux">&nbsp;&nbsp;用户名允许字母、数字、汉字！</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><i style="color:red;">*</i>&nbsp;所属分类</label>
                <div class="layui-input-block">
                    <select name="t_pid" lay-verify="required">
                        <option value="">选择类别</option>
                        {% if type %}
                            <option value="0">顶级栏目</option>
                            {% for da in type %}
                                <option value="{{ da.id }}">{{ da.t_name }}</option>
                            {% endfor %}
                        {% else %}
                            <option value="0">顶级栏目</option>
                        {% endif %}
                    </select>
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">栏目简介</label>
                <div class="layui-input-block">
                    <textarea placeholder="栏目简介" name="t_info" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="hidden" name="id" value="{{ data.id }}" >
                    <button class="layui-btn" lay-submit="" lay-filter="addtype">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>

  </form>
  <!---会员信息区域End-->
</div>
{% endblock %}

{% block setjs %}
<script>
layui.extend({
	admin: '{/}/static/back/js/admin'
});
layui.use(['form','jquery','table','layer'], function() {
	var form = layui.form,
	    table = layui.table,
	    layer = layui.layer,
	    $ = layui.jquery;

    var index = parent.layer.getFrameIndex(window.name); //得到当前iframe层的索引

    //自定义验证规则
    form.verify({
        title: [/^[\u4e00-\u9fa5a-zA-Z0-9]+$/, '用户名允许字母、数字、汉字！']
    });

    //表单初始赋值
    form.val('addform', {
        "t_name": "{{ data.t_name }}"
        ,"t_pid": {{ data.t_pid }}
        ,"t_info": "{{ data.t_info }}"
    });


    //提交
      form.on('submit(addtype)',function(data){
        var addform = $("#addform").serialize();
        console.log(addform)
        //提交数据
        $.ajax({
            async: false,
            data:addform,
            type:'POST',
            dataType: 'json',
            success: function(result) {
                parent.layer.close(index);
                if (result.code == 1) {
                    parent.layer.msg(result.msg, {time: 2000, icon:6,offset: '20px',anim: 6});
                }else{
                    parent.layer.msg(result.msg, {time: 2000, icon:2,offset: '20px',anim: 6});
                }
                parent.location.reload()
            },
            error:function(){
                layer.msg('数据不正确或未知错误', {time: 2000, icon:2,offset: '20px',anim: 6});

            },
            url: "{% url 'typeedit' %}" // 这里写你要验证的地址哦。
        });
        return false;
      });


});

</script>
{% endblock %}





















